package com.maggie.measure.bytecode.javassist;

import javassist.*;

public class Javassist {

    public static void main(String[] args) throws Exception {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.get("com.maggie.measure.bytecode.javassist.Hello");
        CtMethod personFly = cc.getDeclaredMethod("testList");
        cc.addField(CtField.make("public static long cost = 0l;", cc));
        personFly.insertBefore("System.out.println(\"执行方法之前\"); cost = System.currentTimeMillis();");
        personFly.insertAfter("System.out.println(\"执行方法之后 cost =\" + (System.currentTimeMillis() - cost));");
        cc.toClass();
        Hello.testList();
    }

}